package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsAuthDto;
import com.heima.model.wemedia.pojos.NewsRequestDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public PageResponseResult list(@RequestBody NewsRequestDto dto) {
        //1.接收参数
        //2.调用service
        //3.响应结果
        return wmNewsService.list(dto);
    }

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNews wmNews) throws Exception {
        //1.接收参数
        //2.调用service
        //3.响应结果
        return wmNewsService.submit(wmNews);
    }

    /**
     * 根据ID查询自媒体文章
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult<WmNews> one(@PathVariable("id") Integer id) {
        return wmNewsService.one(id);
    }

    /**
     * 上下架
     *
     * @param wmNews
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult down0rUp(@RequestBody WmNews wmNews) {
        return wmNewsService.down0rUp(wmNews);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Integer id) {
        return wmNewsService.delNews(id);
    }

    /**
     * 后台管理端自媒体文章审核文章分页展示
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult listVo(@RequestBody WmNewsAuthDto dto){
        return wmNewsService.listVo(dto);
    }

    /**
     * 后台管理端自媒体文章审核文章详情页面展示
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult oneVo(@PathVariable("id") Integer id) {
        return wmNewsService.oneVo(id);
    }
}
